import pymysql


class ManagerModel():

    def __init__(self):
        # 初始化连接mysql数据库
        self.client = pymysql.connect(host='127.0.0.1', user='root', password='mysql', db='django_demo')

    def get(self):
        pass

    def filter(self):
        pass

    def all(self):
        # 创建游标
        cursor = self.client.cursor(cursor=pymysql.cursors.DictCursor)
        # 指定sql语句
        sql = 'select btitle,bread from tb_books;'
        # 指定sql语句
        cursor.execute(sql)
        # 获取结果
        data = cursor.fetchall()
        return data

    def save(self):
        pass


class Bookinfo():
    """
        自定义的模型类中自带一个objects
    """
    objects = ManagerModel()
